#ifndef ATTRIBUTEHOLDER_H_
#define ATTRIBUTEHOLDER_H_



#include "modules.h"
#include <iostream>
#include <sstream>

class AttributeHolder
{
public:
	static const int REQUEST = 1;
	static const int SESSION = 2;
	static int counter;
	AttributeHolder(std::map<std::string,int> *sessionAttributes);
	virtual ~AttributeHolder();
	int getRequestAttribute(std::string key);
	void setRequestAttribute(std::string key,int pointer);
	int getSessionAttribute(std::string key);
	void setSessionAttribute(std::string key,int pointer);
	void setPool(DataPool *_pool);
	DataPool* getPool();
	
private:
	std::map<std::string,int> requestAttributes;
	std::map<std::string,int> *sessionAttributes;
	DataPool *pool;
};



template<typename type>
class ValueHandler 
{
private:
	int attributeLevel;
	std::string key;

	
public:
	
	ValueHandler(int _attributeLevel) {
		attributeLevel =_attributeLevel;
		std::ostringstream os;
		os << "auto " << ++AttributeHolder::counter;
		key = os.str();
	}
	void set(AttributeHolder *attributes,type *value) {
		switch (attributeLevel) {
		case AttributeHolder::REQUEST:
			attributes->setRequestAttribute(key,(int)value);
			break;
		case AttributeHolder::SESSION:
			attributes->setSessionAttribute(key,(int)value);
			break;
		}
	}
	type* get(AttributeHolder *attributes) {
		switch (attributeLevel) {
				case AttributeHolder::REQUEST:
					return (type*)attributes->getRequestAttribute(key);
					
				case AttributeHolder::SESSION:
					return (type*)attributes->getSessionAttribute(key);
					
				}
		return 0;
	}
};


#endif /*ATTRIBUTEHOLDER_H_*/
